package com.wang.experiment.experiment2;

/**
 * @author wr
 * @date 2021/10/13 21:17
 */
public class Two {
    public static void main(String[] args) {
        Triangle triangle = new Triangle(3,4,5);
        System.out.println("triangle = " + triangle);
        System.out.println("triangle.getPerimeter() = " + triangle.getPerimeter());
        System.out.println("triangle.getArea() = " + triangle.getArea());
        Trapezoid trapezoid = new Trapezoid(2,3,4);
        System.out.println("trapezoid = " + trapezoid);
        System.out.println("trapezoid.getArea() = " + trapezoid.getArea());
        Circle circle = new Circle(5);
        System.out.println("circle = " + circle);
        System.out.println("circle.getPerimeter() = " + circle.getPerimeter());
        System.out.println("circle.getArea() = " + circle.getArea());
    }
}

class Triangle {
    private double sideA;
    private double sideB;
    private double sideC;
    private boolean isTriangle;

    public Triangle(double sideA, double sideB, double sideC) {
        this.sideA = sideA;
        this.sideB = sideB;
        this.sideC = sideC;
        isTriangle = (sideA + sideB > sideC) && (sideB + sideC > sideA) & (sideC + sideA > sideB);
    }

    @Override
    public String toString() {
        return "Triangle{" +
                "sideA=" + sideA +
                ", sideB=" + sideB +
                ", sideC=" + sideC +
                ", isTriangle=" + isTriangle +
                '}';
    }

    public double getPerimeter() {
        return sideA + sideB + sideC;
    }

    public double getArea() {
        double p = (sideA + sideB + sideC) / 2;
        return Math.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
    }

    public double getSideA() {
        return sideA;
    }

    public void setSideA(double sideA) {
        this.sideA = sideA;
        isTriangle = (sideA + sideB > sideC) && (sideB + sideC > sideA) & (sideC + sideA > sideB);
    }

    public double getSideB() {
        return sideB;
    }

    public void setSideB(double sideB) {
        this.sideB = sideB;
        isTriangle = (sideA + sideB > sideC) && (sideB + sideC > sideA) & (sideC + sideA > sideB);
    }

    public double getSideC() {
        return sideC;
    }

    public void setSideC(double sideC) {
        this.sideC = sideC;
        isTriangle = (sideA + sideB > sideC) && (sideB + sideC > sideA) & (sideC + sideA > sideB);
    }

    public boolean isTriangle() {
        return isTriangle;
    }
}

class Trapezoid {
    private double top;
    private double bottom;
    private double height;
    private double area;

    @Override
    public String toString() {
        return "Trapezoid{" +
                "top=" + top +
                ", bottom=" + bottom +
                ", height=" + height +
                ", area=" + area +
                '}';
    }

    public Trapezoid(double top, double bottom, double height) {
        this.top = top;
        this.bottom = bottom;
        this.height = height;
        area = (top + bottom) / 2 * height;
    }

    public double getArea() {
        return area;
    }
}

class Circle {
    private double radius;
    private double perimeter;
    private double area;

    @Override
    public String toString() {
        return "Circle{" +
                "radius=" + radius +
                ", perimeter=" + perimeter +
                ", area=" + area +
                '}';
    }

    public Circle(double radius) {
        this.radius = radius;
        perimeter = 2 * Math.PI * radius;
        area = Math.PI * radius * radius;
    }

    public double getPerimeter() {
        return perimeter;
    }

    public double getArea() {
        return area;
    }
}